<html>
<head>
	<title>MultiSql</title>
	<script type="text/javascript" src="/public/js/jquery-1.10.2.js"></script>
	<script type="text/javascript" src="/public/js/bootstrap.js"></script>
	<link rel="stylesheet" type="text/css" href="/public/css/bootstrap.css">
	<link rel="stylesheet" type="text/css" href="/public/css/sb-admin.css">
	<link rel="stylesheet" type="text/css" href="/public/css/font-awesome.min.css">
</head>
<body style="margin-top: 0px;">
<div class="row">
	<div class="col-lg-12">
		<div class="panel panel-default">
			<div class="panel-heading">
               MultiSql
            </div>
            <div class="panel-body">
            	<div class="row">
            		<div class="col-lg-6">
            			<form role="form">
            				<div class="form-group">
                                <label>Sql:</label>
                                 <textarea id="sql" class="form-control" rows="8"></textarea>
                            </div>
                            <button id="query" type="button" class="btn btn-primary">Query</button>
                            <button id="exec" type="button" class="btn btn-primary">Exec</button>
            			</form>
            		</div>
            	</div>
            </div>
            <div class="panel-footer">
            	<h4>Result:</h4>
            	<span id="r"></span>
            </div>
		</div>
	</div>
</div>
<script type="text/javascript">
	$("#query").click(function(){
		if(window.confirm("Sure to run?")){
			$('#r').empty();
			$.ajax({
				type: "POST",
				url: "/Index/Query",
				data: {sql:$("#sql").val()},
				dataType: "json",
				success: function(data){
                         var html = ''; 
                         for(var i=0;i<data.length;i++){
                         	html+="<b>"+data[i].db+"</b>:"+JSON.stringify(data[i].error)+"<br>";
                         }
                         $('#r').html(html);
                     }
                 });
		}
	});
	$("#exec").click(function(){
		if(window.confirm("Sure to run?")){
			$('#r').empty();
			$.ajax({
				type: "POST",
				url: "/Index/Exec",
				data: {sql:$("#sql").val()},
				dataType: "json",
				success: function(data){
                         var html = ''; 
                         for(var i=0;i<data.length;i++){
                         	html+="<b>"+data[i].db+"</b>:"+JSON.stringify(data[i].error)+"<br>";
                         }
                         $('#r').html(html);
                     }
                 });
		}
	});
</script>
</body>
</html>